Skip to content

Conversation

@szz
Copy link

@szz szz commented Sep 10, 2021

UserManager->createUserRole uses the role key instead of the role name to create a new user, because the role name should be only a human readable value and not a key

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets fixes #issuenum
Related issues/PRs #issuenum
License MIT

What's in this PR?

the commit-msg describes itself

Why?

UserManager->createUserRole uses the role key instead of the role name to create a new user, because the role name should be only a human readable value and not a key
{
/** @var RoleInterface $role */
$role = $this->roleRepository->findOneBy(['name' => $roleName]);
$role = $this->roleRepository->findOneBy(['key' => $roleName]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the pull request! It looks like this is a bug and was forgotten to be changed in #130.

Unfortunately, the new implementation might break things for users that use an older Sulu version. Therefore we need to fallback to the old behaviour like in the InitCommand:

if (\method_exists(Role::class, 'setKey')) {
/** @var RoleInterface|null $role */
$role = $roleRepository->findOneBy(['key' => $roleName, 'system' => $system]);
} else {
// can be removed when min requirement sulu 2.1
/** @var RoleInterface|null $role */
$role = $roleRepository->findOneBy(['name' => $roleName, 'system' => $system]);
}

Also, i think it would be nice to update the code and use roleKey instead of roleName as variable name in the InitCommand, UserManager and UserManagerInterface 🙂

@fnagel
Copy link

fnagel commented Aug 12, 2025

@alexander-schranz Any chance to get this merged? When using the CommunityBundle its not possible to use the "name" field of the user roles as it will break the registration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants